print("我跑完了第%d圈" % 0)

print("%d" % 3.14) # 输出3 
print("%d" % 3.99) # 输出3

print("%6f" % 3.1415926) # 输出
print("%.7f" % 3.1415926) # 输出

report = "%d年%s公司营收增长了百分之%.2f%%" % (2019, "腾讯", 20.28); print(report)

#format函数
#format函数可以格式化多个参数
#输出一个较长的数字，按照国际惯例，每三位用逗号分隔

format_math = '{:,}'.format(1232312312321)
print(format_math)
report = "{0}年{1}公司营收增长了{2}%".format(2019, "腾讯", 20.28) 
print(report)
#{0}表示第一个参数，{1}{2}表示第二、第三个参数，以此类推。这样做的好处是，如果有参数在字符串 出现多次，可以不用重复的传入
report2 = '{0}的GDP为{1:,}...虽然它的GDP只有{1:,}美元，但它的人均GDP高达18万美元'.format("摩纳哥", 7100000000)
print(report2)

#           计算机中，所有的下标都是从0开始的
print("china"[0])


print("china"[0:4])

print("A\tB\tC\nD\tE\tF")

print(" abc ".strip())
print("\t abc \n".strip())


 #将所有字符变成大写
print("china".upper()) # CHINA
# 将字符串的首字母变成大写
print("china".capitalize()) # China
# 将所有字符变成小写
print("CHINA".lower()) # china
# 将每个单词的首字母变成大写
print("i have a dream".title()) # I Have A Dream

print(len("China"))    # 5
print(len(""))     # 0
print(len("a"))    # 1

r = range(10)
len(r)  # 10


sales = (
    ("Peter", (78, 70, 65)),
    ("John", (88, 80, 85)),
    ("Tony", (90, 99, 95)),
    ("Henry", (80, 70, 55)),
    ("Mike", (95, 90, 95)),
)

champion = ''
max_amount = 0
for sale in sales:
    name = sale[0]
    quarter_amount = sale[1]
    total_amount = 0
    for month_amount in quarter_amount:
        total_amount += month_amount
    if total_amount > max_amount:
        max_amount = total_amount
champion = name
print("第一季度的销冠是%s, TA的总销售额是%d万元" % (champion, max_amount))


champion = ''
max_amount = 0
for name, quarter_amount in sales:
    total_amount = sum(quarter_amount)
    if total_amount > max_amount:
        champion, max_amount = name, total_amount 
print("第一季度的销冠是%s, TA的总销售额是%d万元" % (champion, max_amount))


lst = []
lst1 = list()
list2 = [1,2,3]
list3 = ["a", 1, 2, 3, "b", "c"]
print(list3)


print("list[0]: %s"% list3[0])

print("list[1:3] =  %s"% list3[1:3])

list3.append('x')
print(list3)

#删除列表中指定下标的元素
del list3[0]
print(list3)

lst = ['a', 'c', 'e']
# 在第二个元素'c'前面插入一个字符串'b' 
lst.insert(1, 'b')
print(lst)
# lst现在的值是['a', 'b', 'c', 'e']
# 在最后一个元素'e'前面插入一个字符串'd' 
lst.insert(-1, 'd')
print(lst)
# lst现在的值是['a', 'b', 'c', 'd', 'e']


#pop 从列表尾部弹出元素
temp = lst.pop()
print(lst)              # ['a', 'b', 'c', 'd']
print(temp)             # 'e'

# 按位弹出
temp = lst.pop(2)
print(lst)          # ['a', 'b', 'd']
print(temp)         # 'c'

 #删除指定内容的元素，只可以删除第一个匹配到的内容
lst = [1, 2, 1, 'a', 'b', 'c']
lst.remove('a')
print(lst) # lst的值为[1, 2, 1, 'b', 'c'] 
lst.remove(1) # 注意这里的1是元素值，不是索引 
print(lst) # lst的值为[2, 1, 'b', 'c']

#清空列表
lst = [1,2,3,4] 
lst.clear() 
print(lst) # 结果为[]

#列表追加一组数据 extend
lst = []
lst.extend(range(5))
print(lst)      # [0, 1, 2, 3, 4]
lst.extend([5, 6, 7])
print(lst)      # [0, 1, 2, 3, 4, 5, 6, 7]

# reverse 列表反转
lst.reverse()
print(lst)


#sort 从小到大排序
lst.sort()
print(lst)

#在从小到大排序的情况下，转为从大到小
lst.sort(reverse=True)
print(lst)

#按照指定主键排序
revenue = [('1月', 5610000), ('2月', 4850000), ('3月', 6220000)]
revenue.sort(reverse=True, key=lambda x:x[1])
print(revenue)

even_nums = []
for i in range(0, 20, 2):
  even_nums.append(i)

print(even_nums)

for i in range(65, 65 + 26):
    print(i)



top_sales = [('Peter', 213), ('John', 253), ('Tony', 284), ('Henry', 205),('Mike', 280)]
for sale,amount in top_sales:
    if sale == 'Mike':
        print(sale,amount)

#使用花括号，可以直接定义字典
sales = {
  'Peter': 213,
  'John': 253,
  'Tony': 284,
  'Henry': 205,
  'Mike': 280
}

# 定义两个集合
s1 = {1, 2, 3}
s2 = {3, 4, 5}
# 求交集
print(s1)
# 求并集
s3 = s1.union(s2)
print(s3) # {1, 2, 3, 4, 5} # 是否是子集
s1.issubset(s3) # True
print(s1.issubset(s3) )
# 是否是父集
s3.issuperset(s2) # True
print(s3.issuperset(s2))

#####   函数
## 使用def关键字来定义函数
def hello(name):
    print("Hello", name)

hello("aabbcc")



def add(x:int, y:int):   
    return x+y
print(hello.__annotations__)
### 如果一个函数内没有任何return语句，那它的返回值就是None

revenue = [('1月', 5610000), ('2月', 4850000), ('3月', 6220000)]
revenue.sort(reverse=True, key=lambda x:x[1])

# 实现类
class Dog:
    pass
#创建对象
dog = Dog()
#查看dog对象类型
print(type(dog)) #输出：<class '__main__.Dog'>
print(type("aabbcc")) #输出： <class 'str'>

#对象的属性与方法

class Dog:
    # __init__是Python的类用来初始化对象的构造函数
    def __init__(self):
        self.breed = None
        self.color = None
        self.size = None
    def eat(self):
        print("I like bones")
    def run(self):
        print("I'll catch you.")
    def bark(self):
        print('Wang! Wang!')
    def bark(self):
        """一只狗的自我介绍"""
        print('我是一只%s型%s色的%s' % (self.size, self.color, self.breed))

dog = Dog()
dog.eat()
dog.run()
dog.bark()
print('一只%s型%s色的%s' % (dog.size, dog.color, dog.breed))

dog.breed = '哈士奇'
dog.color = '黑白'
dog.size = '大'
print('一只%s型%s色的%s' % (dog.size, dog.color, dog.breed)) # 一只大型黑白色的哈士奇



class Goods:
    count = 0
    def __init__(self):
        Goods.count += 1
        self.name = ''
        self.price = 0
        self.discount = 1

g1 = Goods()
print(g1.count)      # 1
g2 = Goods()
print(g2.count)      # 1
print(Goods.count) # 2

class Goods:
    id_count = 0
    #   这种 @ 符号的写法叫做装饰器，装饰器是用来装饰函数的，不同的装饰器赋予函数不同的特殊功能。
    #   classmethod装饰器，它是用来定义类方法的
    @classmethod
    def generate_id(cls):
        cls.id_count += 1
        return cls.id_count
    def __init__(self):
        # zfill函数表示用“0”将数字补足5位
        self.id = str(self.generate_id()).zfill(5) 
        self.name = ''
        self.price = 0
        self.discount = 1
g1 = Goods()
g2 = Goods()
print(g1.id)       # 00001
print(g2.id)       # 00002
print(Goods.id_count)  # 2


print(dir(Goods))

#help(dog.bark)
help(Dog.bark)















